package com.cwj;

import java.util.concurrent.TimeUnit;

/**
 * @author: Chenwujie
 * @date: 2021-03-22 10:09
 */
public class FinalizeTest {
    public int a = 97;
    public static FinalizeTest OBJ = null;
    String s = "\uD83D\uDE1A";
    public static void main(String[] args) throws InterruptedException {
        OBJ = new FinalizeTest();
        OBJ = null;
        System.gc();
        TimeUnit.MILLISECONDS.sleep(500);
        if(OBJ != null){
            System.out.println("not be GC: "+ OBJ.a);
        }else{
            System.out.println("be GC");
        }

        OBJ = null;
        System.gc();
        TimeUnit.MILLISECONDS.sleep(500);
        if(OBJ != null){
            System.out.println("not be GC: "+ OBJ.a);
        }else{
            System.out.println("be GC");
        }
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        OBJ = this;
    }
}
